
Ext.define('ZYY.view.webdesktop.Wallpaper', {
    extend    : 'Ext.Component',
    alias     : 'widget.webdesktop_wallpaper',
    cls       : 'ux-wallpaper',
    html      : '<img src="'+Ext.BLANK_IMAGE_URL+'">',

    /**
     * @cfg {Boolean} strech status flag if wallpaper should be streched
     */
    stretch   : null,
    /**
     * @cfg {String} wallpaper The current wallpaper file
     */
    wallpaper :null ,
    /**
     * Set the Wallpaper after render
     */
    afterRender: function () {
        var me = this;
        me.wallpaper=wallpapers
        me.callParent();
        me.setWallpaper(me.wallpaper, me.stretch);
    },
    applyState: function () {
        var me = this, old = me.wallpaper;
        me.callParent(arguments);
        if (old != me.wallpaper) {
            me.setWallpaper(me.wallpaper);
        }
    },

    getState: function () {
        return this.wallpaper && { wallpaper: this.wallpaper };
    },
    setWallpaper: function (wallpaper, stretch) {
        var me = this,
            imgEl, bkgnd;
     
        me.stretch   = (stretch !== false);
        me.wallpaper = wallpaper;
        if (me.rendered) {
            imgEl = me.el.dom.firstChild;
            if (!wallpaper || wallpaper == Ext.BLANK_IMAGE_URL) {
                Ext.fly(imgEl).hide();
            } else if (me.stretch) {
                imgEl.src = wallpaper;
                me.el.removeCls('ux-wallpaper-tiled');
                Ext.fly(imgEl).setStyle({
                    width: '100%',
                    height: '100%'
                }).show();
            } else {
                Ext.fly(imgEl).hide();
                bkgnd = 'url('+wallpaper+')';
                me.el.addCls('ux-wallpaper-tiled');
            }

            me.el.setStyle({
                backgroundImage: bkgnd || ''
            });
        }
        return me;
    }
});